
import { _decorator, Component, Node, LabelComponent, Label, sys, game } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('MyMenu')
export class MyMenu extends Component {

    @property(LabelComponent)
    maxLabel:Label|null=null;

    @property(LabelComponent)
    scoreLabel:Label|null=null;
  
    maxScore:number=0

    score:number=0;

    start () {
        let max=sys.localStorage.getItem('max-score');
        if(max){
            this.maxScore=parseInt(max);
        }
        if(this.maxLabel){
            this.maxLabel.string=this.maxScore.toString();
        }
    }

    setMaxScore(score:number){
        if(score>this.maxScore){
            this.maxScore=score;
            sys.localStorage.setItem('max-score',score+'');
        }
        if(this.maxLabel){
            this.maxLabel.string=this.maxScore.toString();
        }
    }

    startGame(){
        this.node.active=false;
        game.emit('game-start');
    }
}
